package com.walnut.controller;

import com.walnut.entity.User;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

/**
 * author: 核桃
 * hello 控制层
 * date: 2023/10/12
 **/
@RestController
public class HelloController {

    @GetMapping("/hello")
    public String hello() {
        return "Hello SpringBoot " + nameAges.toString();
    }

    private static HashMap<String, Integer> nameAges = new HashMap<>();

    @PostMapping("/hello")
    public String helloPost(@RequestParam String name, int age) {
        nameAges.put(name, age);
        return "add name: " + name + ", age=" + age;
    }

    @PostMapping("/hello/body")
    public String helloPostBody(@RequestBody User user) {

        return user.toString();
    }

    @PutMapping("/hello")
    public String helloPut(String name, int age) {
        nameAges.replace(name, age);
        return "update name: " + name + ", age=" + age;
    }

    @DeleteMapping("/hello/{name}")
    public String helloDel(@PathVariable String name) {
        nameAges.remove(name);
        return "delete name: " + name;
    }
}
